package com.itheima.youdianda.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.mapper.SysConfigMapper;
import com.itheima.youdianda.pojo.SysConfig;
import com.itheima.youdianda.service.SysConfigService;
import com.itheima.youdianda.vo.Childrens;
import com.itheima.youdianda.vo.ClassifyConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    @Override
    public R<String> add(SysConfig sysConfig) {
        log.info("要添加的数据{}",sysConfig);
        //添加配置
        if (ObjectUtil.isNotEmpty(sysConfig))
        save(sysConfig);
        return R.success("成功");
    }

    @Override
    //TODO  做不出来
    public R<List<SysConfig>> allList() {



        Childrens children = new Childrens();

        ClassifyConfig classifyConfig=new ClassifyConfig();

       /* //allData 是查询所有数据根据sore
        LambdaQueryWrapper<SysConfig> allWrapper=new LambdaQueryWrapper<>();
        allWrapper.orderByAsc(SysConfig::getSortNum);
        List<SysConfig> allData = list(allWrapper);

        //list是根据tab_value 进行分类  分为了三个类别 基础 系统  其他
              //******基础
        LambdaQueryWrapper<SysConfig> baseWrapper=new LambdaQueryWrapper<>();
         baseWrapper.eq(SysConfig::getTabValue,"base");
        List<SysConfig> baseList = list(baseWrapper);
         classifyConfig.setChildren(baseList);



        //**********系统
        LambdaQueryWrapper<SysConfig> systemWrapper=new LambdaQueryWrapper<>();
        systemWrapper.eq(SysConfig::getTabValue,"system");
        List<SysConfig> systemList = list(systemWrapper);

        //******** 其他
        LambdaQueryWrapper<SysConfig> customWrapper=new LambdaQueryWrapper<>();
        customWrapper.eq(SysConfig::getTabValue,"custom");
        List<SysConfig> customList = list(customWrapper);
*/
/*
        LambdaQueryWrapper<SysConfig> wrapper=new LambdaQueryWrapper<>();
        wrapper.groupBy(SysConfig::getTabValue);
        List<Map<String, Object>> maps = listMaps(wrapper);
        for (Map<String, Object> map : maps) {

            LambdaQueryWrapper<SysConfig> groupWrapper=new LambdaQueryWrapper<>();
            groupWrapper.groupBy(SysConfig::getGroupValue);
            List<Map<String, Object>> groupList = listMaps(groupWrapper);

        }*/




        /*for (SysConfig sysConfig : sysConfigList) {
        }*/

        return R.success(null);
    }
}


